package com.rc.evcharger.common.terminal;


import com.rc.evcharger.common.utils.DataUtil;
import com.rc.evcharger.common.utils.StringUtil;

public class ChargeControlResult extends RecordSource implements Result {
    private Long pileId;//电桩id

    private String gunNum; //枪号；
    private String orderNum; //订单号;
    private String executeResult; //执行结果： 1：启动成功  2：启动失败 3：停止成功 4:停止失败
    private String failReason; //BCD码 启动失败：1.未插枪 2.启动故障 3.正在充电中 4.订单号不符 5.未在充电中
    private String stop; ////00
    private String fault; //00
    private String obligate; //预留字段;

    private String source;

    public Long getPileId() {
        return pileId;
    }

    public void setPileId(Long pileId) {
        this.pileId = pileId;
    }

    public ChargeControlResult(String source, Long pileId) {
        this.source = source;
        this.pileId = pileId;
    }


    public ChargeControlResult() {
        super();
    }

    public String getGunNum() {
        return gunNum;
    }


    public void setGunNum(String gunNum) {
        this.gunNum = gunNum;
    }


    public String getOrderNum() {
        return orderNum;
    }


    public void setOrderNum(String orderNum) {
        this.orderNum = orderNum;
    }


    public String getExecuteResult() {
        return executeResult;
    }


    public void setExecuteResult(String executeResult) {
        this.executeResult = executeResult;
    }


    public String getFailReason() {
        return failReason;
    }


    public void setFailReason(String failReason) {
        this.failReason = failReason;
    }


    public String getStop() {
        return stop;
    }


    public void setStop(String stop) {
        this.stop = stop;
    }


    public String getFault() {
        return fault;
    }


    public void setFault(String fault) {
        this.fault = fault;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getObligate() {
        return obligate;
    }

    public void setObligate(String obligate) {
        this.obligate = obligate;
    }

    @Override
    public ChargeControlResult getResult(String dataStr) {
        dataStr = dataStr.trim();
        //获取枪号
        try {
            this.gunNum = DataUtil.getGunNum(dataStr.substring(0, 2), this.source);
            dataStr = dataStr.substring(3);
            String substring = dataStr.substring(0, 44);
            this.orderNum = StringUtil.getOrderNum(substring);
            dataStr = dataStr.substring(45);
            this.executeResult = dataStr.substring(0, 2);
            dataStr = dataStr.substring(3);
            this.failReason = dataStr.substring(0, 2);
            dataStr = dataStr.substring(3);
            this.stop = dataStr.substring(0, 2);
            dataStr = dataStr.substring(3);
            this.fault = dataStr.substring(0, 2);
            dataStr = dataStr.substring(3);
            this.obligate = dataStr.substring(0, 11);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this;
    }

}
